<template>
  <div>
    <el-dialog v-model="dialogVisible" align-center :title="title">
      <el-form ref="addRef" :model="form" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="学科名称" prop="subjectID">
        <el-select v-model="form.subjectID" placeholder="请选择学科名称" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in subjectIDOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" prop="directoryName">
        <el-input v-model="form.directoryName" placeholder="请输入目录名称" clearable :style="{width: '100%'}">
        </el-input>
      </el-form-item>
      <el-row type="flex" justify="end">
        <el-form-item size="large">
        <el-button type="primary" @click="submitForm">确认</el-button>
        <el-button @click="resetForm">取消</el-button>
      </el-form-item>
      </el-row>
    </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { form } from '@/api/example/form'
import { add } from '@/api/hmmm/directorys'
import { simple as subjectsSimple } from '@/api/hmmm/subjects'
import { title } from 'process'

export default {
  components: {},
  props: {
  },
  data () {
    return {
      title: title,
      dialogVisible: false,
      form: {
        subjectID: undefined,
        directoryName: undefined
      },
      rules: {
        subjectID: [{
          required: true,
          message: '请输入所属学科',
          trigger: 'blur'
        }],
        directoryName: [{
          required: true,
          message: '请输入目录名称',
          trigger: 'blur'
        }]
      },
      subjectIDOptions: [{
        label: '选项一',
        value: 34
      }]
    }
  },
  computed: {},
  watch: {},
  created () {
    this.getSubjectIDOptions()
  },
  mounted () {},
  methods: {
    // 获取学科下拉数据
    async getSubjectIDOptions () {
      const { data } = await subjectsSimple()
      this.subjectIDOptions = data
    },

    submitForm () {
      this.$refs.addRef.validate(async valid => {
        if (!valid) return
        console.log(this.form)
        await add({ ...this.form, id: null }) // 发送请求
        this.dialogVisible = false // 关闭对话框
        this.$message.success('添加成功')
        this.resetForm() // 清空列表
        this.$emit('getcatalogue') // 刷新列表
      })
    },
    resetForm () {
      this.$refs.addRef.resetFields()
      this.dialogVisible = false // 关闭对话框
    }
  }
}

</script>
<style>
</style>
